package com.zr.serviceimpl;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import com.zr.dao.InsertUserDao;
import com.zr.model.Cquestion;
import com.zr.model.Cuser;
import com.zr.service.InsertUserService;

@Service("insertUserService")
public class InsertUserServiceImpl implements InsertUserService{
	
	@Resource
	private InsertUserDao insertUserDao;

	

	@Override
	public int getUrootExistsOrNot(String uroot) {
		
		return insertUserDao.getUrootExistsOrNot(uroot);
	}

	

	@Override
	public void insertUserByInfo(String uroot, String upassword, String uname, String utel, int rid,String question,int cuid,String cuname,String answer) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String time = sdf.format(date);
		String ustate = "正常";
		insertUserDao.insertUserByInfo(uroot, upassword, uname, utel, rid, ustate);
		int uid = insertUserDao.getUidByInfo(uroot);
		int qid = insertUserDao.getQidByQuestion(question);
		StringBuffer infos = new StringBuffer();
		infos.append("编号为");
		infos.append(cuid);
		infos.append("的用户");
		infos.append(cuname);
		infos.append("在");
		infos.append(time);
		infos.append("增加了ID为");
		infos.append(uid);
		infos.append("的用户");
		infos.append(uname);
		String info = infos.toString();
		insertUserDao.insertInfoIntoAnswer(answer, qid, uid);
		insertUserDao.insertInfoIntoLog(time, cuname, uid, info);
	}



	@Override
	public int getRidByRname(String rname) {
		// TODO Auto-generated method stub
		return insertUserDao.getRidByRname(rname);
	}

	


	


}
